home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWGraphx / FWFont.h < prev    next >
Encoding:
Text File  |  1996-12-16  |  8.6 KB  |  301 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFont.h
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWFONT_H
  11. #define FWFONT_H
  12.  
  13. #ifndef SLGRDEF_H
  14. #include "SLGrDef.h"
  15. #endif
  16.  
  17. #ifndef FWSTDDEF_H
  18. #include "FWStdDef.h"
  19. #endif
  20.  
  21. #ifndef FWGCONST_H
  22. #include "FWGConst.h"
  23. #endif
  24.  
  25. #ifndef FWCOLOR_H
  26. #include "FWColor.h"
  27. #endif
  28.  
  29. #ifndef FWGC_H
  30. #include "FWGC.h"
  31. #endif
  32.  
  33. #ifndef SLGDEV_H
  34. #include "SLGDev.h"
  35. #endif
  36.  
  37. #ifndef SLSHATTR_H
  38. #include "SLShAttr.h"
  39. #endif
  40.  
  41. #ifndef FWGRREF_H
  42. #include "FWGrRef.h"
  43. #endif
  44.  
  45. // ----- Foundation Includes -----
  46.  
  47. #ifndef FWSTRING_H
  48. #include "FWString.h"
  49. #endif
  50.  
  51. //========================================================================================
  52. //    Forward Class Declarations
  53. //========================================================================================
  54.  
  55. class FW_CReadableStream;
  56. class FW_CWritableStream;
  57.  
  58. //========================================================================================
  59. //    class FW_CFontMetrics
  60. //========================================================================================
  61. //    For an explanation of why I divide everything by 20 on Windows, look at 
  62. //    FW_CFontMetrics::PrivGetFontMetrics
  63.  
  64. class FW_CFontMetrics : public FW_PlatformFontMetrics
  65. {
  66. public:
  67.     short    GetAscent() const;
  68.     short    GetDescent() const;
  69.     short    GetInternalLeading() const;
  70.     short    GetExternalLeading() const;
  71.     short    GetFontHeight() const;
  72.     short    GetLineSpacing() const;
  73.     
  74.     static void    PrivGetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics);
  75. };
  76.  
  77. //========================================================================================
  78. //    CLASS FW_CFont
  79. //========================================================================================
  80.  
  81. class FW_CFont : public FW_TGrRefPtr<FW_HFont>
  82. {
  83. public:
  84.     FW_DECLARE_AUTO(FW_CFont)
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    Constructors/Destructor
  88. //
  89. public:
  90.     FW_CFont(FW_EStandardFonts std = FW_kNormalFont);
  91.     FW_CFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize);
  92.     FW_CFont(const FW_CFont& other);
  93.     
  94.     ~FW_CFont();
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    operators
  98. //
  99. public:
  100.     FW_CFont& operator=(const FW_CFont& other);
  101.  
  102.     FW_CFont& operator=(FW_EStandardFonts std);
  103.     
  104.     friend FW_CWritableStream& operator << (FW_CWritableStream& stream, const FW_CFont& font);
  105.     friend FW_CReadableStream& operator >> (FW_CReadableStream& stream, FW_CFont& font);
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    New API
  109. //
  110. public:
  111.     // ----- Copy -----
  112.     FW_CFont            Copy() const;
  113.  
  114.     // ----- Font Metrics -----
  115.     void                GetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics) const;
  116.     void                GetFontMetrics(FW_CGraphicContext& gc, FW_CFontMetrics& fontMetrics) const;
  117.  
  118.     // ----- Delegation
  119.     long                GetRefCount() const;
  120.  
  121.     // Attributes
  122.     
  123.     FW_Fixed            GetFontSize() const;
  124.     FW_FontStyle        GetFontStyle() const;
  125.     void                GetFontName(FW_CString& fontName) const;
  126.     void                GetPlatformFontName(FW_CString& fontName) const;
  127.     
  128.     // Comparison
  129.     
  130.     FW_Boolean            IsEqual(const FW_CFont& font2) const;
  131.     
  132.     // Operations
  133.     
  134.     void                SetFontSize(FW_Fixed size);
  135.     void                SetFontStyle(FW_FontStyle style);
  136.     void                SetFontName(const FW_CString& fontName);
  137.     
  138.     // ----- Conversion -----
  139.     static FW_FontStyle    PlatformToODFFontStyle(const FW_PlatformFontStyle& platformStyle);
  140.     
  141.     // Macintosh-only
  142. #ifdef FW_BUILD_MAC
  143.     short                    MacGetFontID() const;
  144.     FW_PlatformFontStyle    MacGetFontStyle() const;
  145.     
  146.     void                    MacSetFontID(short macFontID);
  147. #endif
  148. };
  149.  
  150. //========================================================================================
  151. //    Inlines
  152. //========================================================================================
  153.  
  154. //----------------------------------------------------------------------------------------
  155. //    FW_CFont::GetRefCount
  156. //----------------------------------------------------------------------------------------
  157. inline long FW_CFont::GetRefCount() const
  158. {
  159.     return FW_PrivFont_GetRefCount(fRep);
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CFont::GetFontSize
  164. //----------------------------------------------------------------------------------------
  165. inline FW_Fixed FW_CFont::GetFontSize() const
  166. {
  167.     return FW_PrivFont_GetSize(fRep);
  168. }
  169.  
  170. //----------------------------------------------------------------------------------------
  171. //    FW_CFont::GetFontStyle
  172. //----------------------------------------------------------------------------------------
  173. inline FW_FontStyle FW_CFont::GetFontStyle() const
  174. {
  175.     return FW_PrivFont_GetStyle(fRep);
  176. }
  177.  
  178. //----------------------------------------------------------------------------------------
  179. //    FW_CFont::IsEqual
  180. //----------------------------------------------------------------------------------------
  181. inline FW_Boolean FW_CFont::IsEqual(const FW_CFont& font2) const
  182. {
  183.     return FW_PrivFont_IsEqual(fRep, font2.fRep);
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    FW_CFont::SetFontSize
  188. //----------------------------------------------------------------------------------------
  189. inline void FW_CFont::SetFontSize(FW_Fixed size)
  190. {
  191.     FW_PrivFont_SetSize(fRep, size);
  192. }
  193.  
  194. //----------------------------------------------------------------------------------------
  195. //    FW_CFont::SetFontStyle
  196. //----------------------------------------------------------------------------------------
  197. inline void FW_CFont::SetFontStyle(FW_FontStyle style)
  198. {
  199.     FW_PrivFont_SetStyle(fRep, style);
  200. }
  201.  
  202. #ifdef FW_BUILD_MAC
  203. //----------------------------------------------------------------------------------------
  204. //    FW_CFont::MacGetFontID
  205. //----------------------------------------------------------------------------------------
  206. inline short FW_CFont::MacGetFontID() const
  207. {
  208.     return FW_PrivFont_MacGetFontID(fRep);
  209. }
  210. #endif
  211.  
  212. #ifdef FW_BUILD_MAC
  213. //----------------------------------------------------------------------------------------
  214. //    FW_CFont::MacGetFontStyle
  215. //----------------------------------------------------------------------------------------
  216. inline Style FW_CFont::MacGetFontStyle() const
  217. {
  218.     return FW_PrivFont_MacGetFontStyle(fRep);
  219. }
  220. #endif
  221.  
  222. //----------------------------------------------------------------------------------------
  223. //    FW_CFontMetrics::GetLineSpacing
  224. //----------------------------------------------------------------------------------------
  225. inline short FW_CFontMetrics::GetLineSpacing() const
  226. {
  227. #ifdef FW_BUILD_MAC
  228.     return ascent + descent + leading;
  229. #endif
  230. #ifdef FW_BUILD_WIN
  231.     return tmHeight / 20;
  232. #endif
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. //    FW_CFontMetrics::GetAscent
  237. //----------------------------------------------------------------------------------------
  238. inline short FW_CFontMetrics::GetAscent() const
  239. {
  240. #ifdef FW_BUILD_MAC
  241.     return ascent;
  242. #endif
  243. #ifdef FW_BUILD_WIN
  244.     return tmAscent / 20;
  245. #endif
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    FW_CFontMetrics::GetDescent
  250. //----------------------------------------------------------------------------------------
  251. inline short FW_CFontMetrics::GetDescent() const
  252. {
  253. #ifdef FW_BUILD_MAC
  254.     return descent;
  255. #endif
  256. #ifdef FW_BUILD_WIN
  257.     return tmDescent / 20;
  258. #endif
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //    FW_CFontMetrics::GetExternalLeading
  263. //----------------------------------------------------------------------------------------
  264. inline short FW_CFontMetrics::GetExternalLeading() const
  265. {
  266. #ifdef FW_BUILD_MAC
  267.     return 0;
  268. #endif
  269. #ifdef FW_BUILD_WIN
  270.     return tmExternalLeading / 20;
  271. #endif
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    FW_CFontMetrics::GetInternalLeading
  276. //----------------------------------------------------------------------------------------
  277. inline short FW_CFontMetrics::GetInternalLeading() const
  278. {
  279. #ifdef FW_BUILD_MAC
  280.     return leading;
  281. #endif
  282. #ifdef FW_BUILD_WIN
  283.     return tmInternalLeading / 20;
  284. #endif
  285. }
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    FW_CFontMetrics::GetFontHeight
  289. //----------------------------------------------------------------------------------------
  290. inline short FW_CFontMetrics::GetFontHeight() const
  291. {
  292. #ifdef FW_BUILD_MAC
  293.     return ascent + descent;
  294. #endif
  295. #ifdef FW_BUILD_WIN
  296.     return (tmHeight - tmInternalLeading) / 20;
  297. #endif
  298. }
  299.  
  300. #endif
  301.